package com.sgb.kjwl.view.widget;

import android.content.Context;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.GoodsInfoTypeEntity3;
import com.sgb.kjwl.view.ui.adapter.transport.GoodsTypeAdapter3;
import com.sgb.kjwl.view.ui.adapter.transport.GoodsTypeAdapter4;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.List;

public class GoodsTypePopWindow4 extends BasePopWindow {

    private GoodsTypeAdapter4 goodsTypeAdapter;
    private GoodsInfoTypeEntity3 currentItem;

    public GoodsTypePopWindow4(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_goods_types_4;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        RecyclerView recyclerView = holder.getPop().findViewById(R.id.type_list);

        goodsTypeAdapter = new GoodsTypeAdapter4(mContext, null);
        goodsTypeAdapter.setItemSelect(true);
        goodsTypeAdapter.setDefItem(0);
        recyclerView.setLayoutManager(new GridLayoutManager(mContext, 4));
        recyclerView.setAdapter(goodsTypeAdapter);

        goodsTypeAdapter.setOnItemClick(new AdapterOnItemClick<GoodsInfoTypeEntity3>() {
            @Override
            public void onItemClick(GoodsInfoTypeEntity3 provinceEntity, int position) {
                onResultClick.result(provinceEntity, position, null);
                currentItem = provinceEntity;
                dissMiss();
            }
        });

        //设置背景
        setBgView(holder.getPop().findViewById(R.id.bg_pop_gray_layout));
    }

    public void setData(List<GoodsInfoTypeEntity3> list, int position) {
        goodsTypeAdapter.setDatas(list);
        goodsTypeAdapter.setDefItem(position);
    }

    public void setDefItem(int position) {
        goodsTypeAdapter.setDefItem(position);
    }

    public boolean isSetGoodstype() {
        return currentItem != null;
    }

    public String getGoodsTypeStr() {
        return currentItem.getName();
    }

    public void resetSelectItem() {
        goodsTypeAdapter.setDefItem(0);
        goodsTypeAdapter.resetCheckDatas();
    }

}
